#include <bits/stdc++.h>
using namespace std;

const int N = 1005, M = 1e4 + 5;

struct Edge {
  int to, w, next;
} e[M << 1];

int h[N], tot;

void add(int u, int v, int w) {
  e[tot].to = v, e[tot].w = w, e[tot].next = h[u], h[u] = tot++;
}

int d[N];
bool vis[N];
int n, m, k;

bool dijk(int lim) {
  memset(d, 0x3f, sizeof d);
  memset(vis, false, sizeof vis);
  d[1] = 0;
  deque<int> q;
  q.push_back(1);

  while (q.size()) {
    int u = q.front();
    q.pop_front();
    if (vis[u]) continue;
    vis[u] = true;

    for (int i = h[u]; ~i; i = e[i].next) {
      int go = e[i].to;
      if (d[go] > d[u] + (e[i].w > lim)) {
        d[go] = d[u] + (e[i].w > lim);
        if (e[i].w > lim)
          q.push_back(go);
        else
          q.push_front(go);
      }
    }
  }

  return d[n] <= k;
}

int main() {
  memset(h, -1, sizeof h);
  cin >> n >> m >> k;

  while (m--) {
    int u, v, w;
    cin >> u >> v >> w;
    add(u, v, w), add(v, u, w);
  }

  // binary search
  int l = 0, r = 1e6 + 1;
  while (r > l) {
    int mid = (r + l) >> 1;
    if (dijk(mid))
      r = mid;
    else
      l = mid + 1;
  }

  if (r != 1e6 + 1)
    cout << r << endl;
  else
    cout << -1 << endl;

  return 0;
}
